﻿/* ==============================================================================
  * Description：
  * By Se7en
  * Creation Time：[2013-09-22 18:34:10]
  * @version 1.0
  * ==============================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BML.Infrastructure;
using BML.Infrastructure.Implement;
using FrameCase.Infrastructure;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Model.BusinessLogic.PhysicalData;
using Service;
using Service.Infrastructure.Interface;

namespace FrameCase
{
    /// <summary>
    /// ServiceCase
    /// Description：测试Service层方法并提供范例
    /// </summary>
    [TestClass]
    public class ServiceCase:BaseCase
    {
        protected BaseOperator op = new BaseOperator();

        [TestMethod]
        public void Normal()
        {
            IAccount account = ServiceFactory.GMember();
            Object obj = ServiceFactory.GMember();
            account.Login("userKey", Guid.NewGuid(), obj, "", "1", 2, new object());
        }


        #region normal operator is a case
        
        
        [TestMethod]
        public void CreateEntity()
        {
            for (int i = 990;i<1001;i++)
            {
                op.Create(new Tag
                {
                    Id = Guid.NewGuid(),
                    CreateTime = DateTime.Now,
                    Name = String.Format("{0}--Name",i),
                    CustomKey = i,
                });
                
            }
            
        }

        [TestMethod]
        public void ReadEntity()
        {
            var list = op.Read<Tag>(n => n.CustomKey == 1000).Select(m=>m.Name).ToList();
            ConsoleList(list);
        }

        [TestMethod]
        public void ReadAll()
        {
            var list = op.ReadAll<Tag>().Select(m => m.Name).ToList();
            ConsoleList(list);
        }

        [TestMethod]
        public void UpdateEntity()
        {
            op.Update<Tag>(m=> m.CustomKey < 995,n=>new Tag{Name = "1000" });
        }

        [TestMethod]
        public void DeleteEntitiy()
        {
            op.Delete<Tag>(m=>m.Name == "1000");
        }







        #endregion

        [TestMethod]
        public void ExceptionHandle()
        {
            try
            {
                throw new InvalidOperationException();
            }
            catch (Exception e)
            {
                Type t =e.GetType();
                Console.WriteLine(e.InnerException);
            }
        }

        [TestMethod]
        public void CreateManager()
        {
            ManagerOp op  = new ManagerOp();
            op.CreateAdministrater("admin","dongyan","se7en",1);
        }

    }
}
